<!DOCTYPE html
     PUBLIC "-//W3C//DTD XTHML 1.0 Strict//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
    <link rel="stylesheet" type="text/css" href="styles.css" />
    <title>uthash: a hash table for C structures</title>
  </head>
  <body>

  <div id="banner">
  <img src="img/banner.png" alt="uthash: a hash table for C structures" />
  </div> <!-- banner -->

  <div id="topnav">
  <a href="http://sourceforge.net/projects/uthash/">sf.net summary page</a> &gt;
  uthash home
  </div>

  <hr />
  <div id="mid">

      <div id="nav">

        <h2>documentation</h2>
        <div><a href="userguide.html">user guide</a> [<a href="userguide.html">html</a>] [<a href="userguide.pdf">pdf</a>]</div>

        <h2>download</h2>
        <div><a href="http://downloads.sourceforge.net/uthash/uthash-1.6.tar.bz2">uthash-1.6.tar.bz2</a></div>

        <h2>last release</h2>
        <div>May, 2009</div>
        <div><a href="ChangeLog.html">ChangeLog</a></div>

        <h2>license</h2>
        <div><a href="license.html">BSD revised</a></div>

        <h2>resources</h2>
        <div><a href="http://troydhanson.wordpress.com/">updates</a> [<a href="http://troydhanson.wordpress.com/feed/">rss</a>]<img alt=" rss" src="img/rss.png"/></div>
        <div><a href="utlist.html">linked list macros</a> </div>

        <h2>other projects</h2>
        <div><a href="http://tpl.sourceforge.net/">tpl</a></div>

        <h2>developer</h2>
        <div>Troy D. Hanson</div>

      </div>


      <div id="main">
        Any C structure can be stored in a hash table using uthash. Just add a
        <em>UT_hash_handle</em> to the structure and choose one or more fields
        in your structure to act as the key. Then use these macros to store,
        retrieve or delete items from the hash table.

<div class="listing">
Example 1. Adding an item to a hash.
<div class="code">
<pre>
#include "uthash.h"

struct my_struct {
    int id;                  /* we'll use this field as the key */
    char name[10];             
    UT_hash_handle hh;       /* makes this structure hashable */
};

struct my_struct *users = NULL;

void add_user(struct my_struct *s) {
    HASH_ADD_INT( users, id, s );    
}

</pre>
</div> <!-- code -->
</div> <!-- listing -->

<div class="listing">
Example 2. Looking up an item in a hash.
<div class="code">
<pre>
struct my_struct *find_user(int user_id) {
    struct my_struct *s;

    HASH_FIND_INT( users, &amp;user_id, s );  
    return s;
}

</pre>
</div> <!-- code -->
</div> <!-- listing -->

<div class="listing">
Example 3. Deleting an item from a hash.
<div class="code">

<pre>
void delete_user(struct my_struct *user) {
    HASH_DEL( users, user);  
}

</pre>
</div> <!-- code -->
</div> <!-- listing -->

 For more information and examples, please see the <a href="userguide.html">User Guide.</a>

</div> <!-- main -->
</div> <!-- mid -->

   <hr />
  <div id="footer">
    <a href="http://sourceforge.net/projects/uthash"><img src="http://sflogo.sourceforge.net/sflogo.php?group_id=163879&amp;type=13" width="120" height="30" alt="Get uthash at SourceForge.net. Fast, secure and Free Open Source software downloads" /></a>
    <p>This project is hosted on SourceForge.net</p>
    <p>$Id: index.html 87 2009-05-04 23:37:03Z thanson $</p>
  </div> <!-- footer -->

  </body>

</html>

